var now_page_num = 0; //当前轮播图索引
var old_page_num=0;//旧的轮播图索引
var box_items_a = document.getElementsByClassName("box-items-a")[0];
//图片
var imgs = box_items_a.getElementsByTagName("a");


var box_items_btn_b1 = document.getElementsByClassName("box-items-btn-b1")[0];
//小按钮
var points = box_items_btn_b1.getElementsByTagName("a");
var item_btn_prev=document.getElementsByClassName("item-btn-prev")[0];
var item_btn_next=document.getElementsByClassName("item-btn-next")[0];

var timer = null;// 计时器
var s = 3000; //秒数

//设置所有的图片 透明度为0
function imgs_hidden() {
	for (let i = 0; i < imgs.length; i++) {
		imgs[i].style.opacity=0;
	}
}
//清空的小按钮背景色
function points_hidden() {
	for (let i = 0; i < points.length; i++) {
		points[i].className = "";
	}
}

function changeAll() {
	imgs_hidden();
	points_hidden();
	imgs[now_page_num].style.opacity=1;
	points[now_page_num].className = "active";
}
changeAll();

function bannerplay() {
	timer = setInterval(function() {
		now_page_num++;
		if (now_page_num > imgs.length - 1) {
			now_page_num = 0;
		}
		changeAll();
	}, s)
}
bannerplay();//自动播放

item_btn_next.onmouseover=item_btn_prev.onmouseover= function() {
		clearInterval(timer);
}
item_btn_next.onmouseout=item_btn_prev.onmouseout= function() {
		bannerplay();
}
for (let i = 0; i < points.length; i++) {
	points[i].index = i;
	imgs[i].onmouseover = points[i].onmouseover = function() {
		clearInterval(timer);
	}
	
	imgs[i].onmouseout = points[i].onmouseout = function() {
		bannerplay();
	}

	points[i].onclick = function() {
		now_page_num = this.index;
		changeAll();
	}
}
// 上一张
function prev() {
	now_page_num--;
	if (now_page_num < 0) {
		now_page_num = imgs.length - 1;
	}
	changeAll();
}
// 下一张
function next() {
	now_page_num++;
	if (now_page_num > imgs.length - 1) {
		now_page_num = 0;
	}
	changeAll();
}

